package com.foreknow.demo5;

import javax.swing.*;

public class EmployeeManager {

    int count;//默认值为 0;
    private Employee[] employees;


    public EmployeeManager() {
        employees = new Employee[10];
    }

    /**
     * 添加员工
     * 员工信息要求从控制台输入
     */
    public void add(Employee emp) {
        if (emp != null) {
            if (count < 10) {
                employees[count] = emp;
                count++;
                System.out.println("添加成功！");
            } else {
                System.out.println("添加失败！");
            }
        }
    }

    /**
     * 查询所有员工信息
     */
    public Employee[] selectAll() {
        Employee[] arr = null;
        Employee a = null;
        for (int i = 0;i<count;i++) {
            arr[i] = a;
        }
    return arr;
    }

    /**
     * 根据id查询对应的员工信息
     */

    public Employee select(String id) {
        //先对employees数组进行遍历
        //判断数组中对象的id是否与参数传进来的id相同
        //如果相同就将这个对象从数组中获取并以方法的最终结果返回
        Employee e = null;
        for (int i = 0;i<count;i++) {
            if (employees[i].getStaffid().equals(id)) {
                e = employees[i];
            }
        }

        return e;
    }

    public static void main(String[] args) {
        Employee[] emp1 = new Employee[4];
    }
}
